/***************************************************************************************************
  Copyright(C)   2011-9-5
  All rights reserved.
  File Name: clientservice.h

  Description:配置模块TCP多线程服务端线程管理块
             主要是对每一个客户端的连接开户一个特定的线程来处理

  ***************************************************************************************************/

#ifndef TCPSERVER_H
#define TCPSERVER_H

#include <QTcpServer>

#include "clientservicethread.h"
#include "log.h"
#include "configclass.h"

class TcpServer : public QTcpServer
{
    Q_OBJECT

    LOG4QT_DECLARE_QCLASS_LOGGER

public:
    explicit TcpServer(int state = 0, QObject *parent = 0);
    ~TcpServer();

//    void sendSysState();
    void closeClient();
    void setSystemState(const SystemState &state);

protected:
    void incomingConnection(int socketID);

signals:
    void receFeedData(const FreedDogStruct& freedDogStruct);
    void serviceInfoSignal(const QString& fileName, const int fileLen);           //发送更新服务器信息
    void updateService(const int state, const int fileCount);


    void sendDebugMsg(const QString& msg);

    void delteThread();

    void sendBrihgtness(const qint16 brightness);

    void receChangeBriLv(const LcdSettingStruct& settingStruct);            //收到改变LCD 亮度等级信息
    void receSetLcdIDListCmd(const QMap<qint16, qint8>& lcdState);

    void receSetLcdSettingsCmd(const LcdSettingStruct& lcdSettings);

    //收到要改变LCD亮度信号
    void receChangeLcdBright(const qint16 brightness, const QList<quint16>& panelIDList);

//    void receGetLcdStateCmd();
    void receGetLcdStatus();                                               //申请获得LCD的状态

    void getLcdSetting();

    void sendSetLcdSettingStatus(const qint8 state);
//    void sendSetLcdTraValueStatus(const qint8 state);

    void sendBackLightStatus(qint8 status);
    void sendVideoStatus(const QList<LCDSTATUS>& status, const bool isSendToTis);
    void sendLcdSetting(const LcdSettingStruct& lcdSettings);

    void receLcdBackLightCtl(const qint8 cmd, const QList<quint16>& panelIDList);

    void receQueryVideoStatus(const qint8 cmd);

    void receSlcdCollectState(const QList<PanelInfoStruct>& infoList);

    //配置已经进行更新，必须重新读取配置
    void updateConfig();

    void sendSetLcdTraValueStatus(const qint8);

    void receSystemState(const SystemState& state);

    void clientConIn();

    void receCheckLcdCmd(const qint8 cmd);      //收到检测LCD屏的命令

    //lcd回复状态,包括亮度设置和背景灯设置这２个设置
    void lcdAnswerStatus(QList<LCDSTATUS> status);

private:
    int serverState;
    int connectCount;

    QList<ClientServiceThread *> threadList;


private slots:
    void threadFinish();


};

#endif // TCPSERVER_H
